#include "Chronometer.h"

/*
 *--------------------------------------------------------------------------------------
 *       Class:  Chronometer
 *      Method:  Chronometer
 * Description:  Constrói um cronômetro, começando o contador
 *--------------------------------------------------------------------------------------
 */
Chronometer::Chronometer()
{
    reset();
}

/*
 *--------------------------------------------------------------------------------------
 *       Class:  Chronometer
 *      Method:  reset
 * Description:  Reseta o cronômetro
 *--------------------------------------------------------------------------------------
 */
void Chronometer::reset()
{
    clock_gettime(CLOCK_REALTIME, &init);
}

/*
 *--------------------------------------------------------------------------------------
 *       Class:  Chronometer
 *      Method:  getSeconds
 * Description:  Retorna o tempo atual em segundos
 *--------------------------------------------------------------------------------------
 */
double Chronometer::getSeconds()
{
    struct timespec end;
    clock_gettime(CLOCK_REALTIME, &end);
    double time = (end.tv_sec - init.tv_sec) + (end.tv_nsec - init.tv_nsec) / (double) 1000000000;
    return time;
}

/*
 *--------------------------------------------------------------------------------------
 *       Class:  Chronometer
 *      Method:  getMiliseconds
 * Description:  Retorna o tempo atual em milisegundos
 *--------------------------------------------------------------------------------------
 */
double Chronometer::getMiliseconds()
{
    struct timespec end;
    clock_gettime(CLOCK_REALTIME, &end);
    double time = (end.tv_sec - init.tv_sec) * 1000 + (end.tv_nsec - init.tv_nsec) / (double) 1000000;
    return time;
}

